<?php

namespace app\api\controller\user;

use app\api\controller\Controller;
use app\api\model\user\CouponLog as CouponLogModel;

/**
 * 用户返现劵
 * Class Coupon
 * @package app\api\controller
 */
class Couponlog extends Controller
{
    /* @var CouponLogModel $model */
    private $model;

    /* @var \app\api\model\User $model */
    private $user;

    /**
     * 构造方法
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new CouponLogModel;
        $this->user = $this->getUser();
    }

    /**
     * 返现券列表
     * @param string $dataType
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function lists($dataType = 'not_use')
    {
        $list = $this->model->getList($this->user['user_id'], $dataType);
        return $this->renderSuccess(compact('list'));
    }

    /**
     * 返现劵详情
     * @param $log_id
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function detail($log_id)
    {
        $coupon = CouponLogModel::getCouponLogDetail($log_id, $this->user['user_id']);
        return $this->renderSuccess(compact('coupon'));
    }


    /**
     * 可用返现券列表
     * @param $goods_id
     * @param $goods_num
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function allow($goods_id, $goods_num, $goods_sku_id)
    {
        $couponList = $this->model->getAllowCouponList($this->user['user_id'], $goods_id, $goods_num, $goods_sku_id);
        return $this->renderSuccess(compact('couponList'));
    }


}